%% -*- mode: erlang -*-

%% Adapted version of apps/zotonic_launcher/priv/config/erlang.config.in
%% - Paths are set to /opt/zotonic/priv/...

[

 {exometer_core, [{predefined, [
    {[erlang, memory], {function, erlang, memory, [], value, []}, []},
    {[erlang, system_info], {function, erlang, system_info, ['$dp'], value, [process_count]}, []},
    {[erlang, statistics], {function, erlang, statistics, ['$dp'], value, [run_queue]}, []},
    {[erlang, io], {function, erlang, statistics, [io], match, {{'_', input}, {'_', output}}}, []}
   ]}
 ]},

 % ZOTONIC_DATA_DIR is mapped to docker-data/data
 % ZOTONIC_LOG_DIR is mapped to docker-data/logs

 {kernel, [
    % Minimum log level for all loggers below.
    {logger_level, info},

    {logger, [

        %% To use logstash:
        %% - Enable the logstasher_h handler
        %% - Configure logstasher (see below the kernel config)
        %%
        % {handler, logstash, logstasher_h,
        %     #{
        %         level => info
        %     }
        % },

        % Log of all information to the terminal/console.
        % The 'logger_level' above defines what is shown on the console.
        {handler, default, z_logger_h,
            #{
                level => debug,
                formatter => {z_logger_formatter,
                    #{
                        prettify => true,
                        colored => true,
                        time_designator => $\s,
                        time_offset => "",
                        time_unit => second,
                        strip_tz => true,
                        level_capitalize => true
                    }
                }
            }
        },

        % Error log on disk.
        % LOG_DIR is replaced with the default Zotonic ZOTONIC_LOG_DIR directory.
        {handler, error_log, z_logger_h,
            #{
                level => error,
                config => #{
                    type => file,
                    file => "LOG_DIR/error.log",
                    max_no_files => 10,
                    max_no_bytes => 52428800 % 10 x 5mb
                },
                formatter => {z_logger_formatter,
                    #{
                        prettify => true,
                        colored => false,
                        time_designator => $\s,
                        time_offset => "",
                        time_unit => second,
                        strip_tz => true,
                        level_capitalize => true
                    }
                }
            }
        },

        % Console log on disk.
        % LOG_DIR is replaced with the default Zotonic ZOTONIC_LOG_DIR directory.
        {handler, console_log, z_logger_h,
            #{
                level => debug,
                config => #{
                    type => file,
                    file => "LOG_DIR/console.log",
                    max_no_files => 10,
                    max_no_bytes => 52428800 % 10 x 5mb
                },
                formatter => {z_logger_formatter,
                    #{
                        prettify => true,
                        colored => false,
                        time_designator => $\s,
                        time_offset => "",
                        time_unit => second,
                        strip_tz => true,
                        level_capitalize => true
                    }
                }
            }
        }
    ]}
 ]},

 %% Logstash configuration.
 %% If a logger handler with 'logstasher_h' is defined then zotonic_core will start the
 %% logstasher application.
 {logstasher, [
    {transport, console}, % tcp | udp | console
    {host, "localhost"},  % inet:hostname()
    {port, 5000}          % inet:port_number()
 ]},

 {ssl, [
   %%% The number of maximum number of ssl sessions cached by the server. Increase if you
   %%% of a lot of incoming connections.
   {session_cache_server_max, 20000},

   %%% The maximum time the client side information is stored in the cache (in seconds)
   {session_lifetime, 300}
 ]}

].
